package k.web.cityManage;

import com.alibaba.fastjson.JSON;
import k.HelperClazz;
import k.dao.base.RoleDao;
import k.dto.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * Created by sure on 2018/4/12.
 */
@Controller
@RequestMapping(value = "/role")
public class RoleController {
    @Autowired
    private RoleDao roleDao;
    /**
     * 角色管理主页面
     * @param model
     * @param request
     * @return
     */
    @RequestMapping(value = "/roleIndex")
    public String index(Model model, HttpServletRequest request) {
        model.addAttribute("emp_id", HelperClazz.getEMP().getEmp_id());
        model.addAttribute("emp_name", HelperClazz.getEMP().getEmp_name());
        //查询所有角色
        model.addAttribute("roles",roleDao.findAll());
        return "system_manage/roleIndex";
    }

    @RequestMapping(value = "/queryRole")
    public void queryRole(String roleId,HttpServletResponse response){
        HelperClazz.renderJson(response, JSON.toJSONString( roleDao.querybyId(roleId)));
    }

    @RequestMapping(value = "/roleSave")
    public String roleSave(Role role, HttpServletResponse response){
        roleDao.upd(role);
        return "redirect:/role/roleIndex";

    }

}
